﻿using System;

namespace CSharp进阶_协变逆变
{
	delegate T TestOut<out T>();
	interface ITestOut<out T>
	{
		T Print();
	}
	delegate void TestIn<in T>(T t);
	interface ITestIn<in T>
	{
		void Print(T t);
	}
	class Base
	{

	}
	class Derived : Base
	{

	}
	class Program
	{
		static void Main(string[] args)
		{
			// 协变
			TestOut<Derived> td = () =>
			{
				return new Derived();
			};
			TestOut<Base> tb = td;
			Base b = tb();

			// 逆变
			TestIn<Base> tib = (Base d) =>
			{
			};
			TestIn<Derived> tid = tib;
			tid(new Derived());

			//TestOut<int> testOut = Func1<int>;
			//testOut += () => { Console.WriteLine("testOut = () => { Console.WriteLine(); return 1; };"); return 1; };
			//testOut();

			//TestIn<string> testIn = (string str) =>
			//{
			//	Console.WriteLine(str);
			//};
			//testIn("dawdadawdwadawwda");
		}
		static T Func1<T>() 
		{
			Console.WriteLine("static T Func1<T>() ");
			return default(T);
		}
	}
}
